package mypackage;

import java.util.Scanner;

//金额转换,将输入的数字转成大写
public class MoneyToBig {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入0-9,999,999的金额");
        while (true) {
            int money = sc.nextInt();
            if (money < 0 || money > 10000000) {
                System.out.println("输入的金额不合法");
                System.out.println("请重新输入");
            } else {
                String moneyString = getString(money);
                String moneyBigString = getBigString(moneyString);
                String ans = reverseString(moneyBigString);
                System.out.println(ans);
                break;
            }
        }
    }

    public static String getString(int num) {
        String str = "";
        String shu = "零壹贰叁肆伍陆柒捌玖";
        int temp = num;
        while (temp > 0) {
            char c = shu.charAt(temp % 10);
            str = c + str;
            temp /= 10;
        }
        return str;
    }

    public static String getBigString(String money) {
        String face = "佰拾万仟佰拾元";
        String ans = "";
        int l = money.length() - 1;
        int r = face.length() - 1;
        while (l >= 0 && r >= 0) {
            ans = ans + face.charAt(r);
            ans = ans + money.charAt(l);
            --r;
            --l;
        }
        String zero = "零";
        while (r >= 0) {
            ans = ans + face.charAt(r);
            ans = ans + zero;
            --r;
        }
        return ans;
    }

    public static String reverseString(String str) {
        String ans = "";
        for (int i = 0; i < str.length(); i++) {
            ans = str.charAt(i) + ans;
        }
        return ans;
    }
}
